<?php
/**
 * This is the file to define DatabaseException.
 * 
 * @author	Justin Yoo
 * @version	0.0.1.0001
 * @package	KYR.Core
 * 
 */

//	Checks if this file is called within the framework; otherwise terminates.
if (!defined("IS_FRAMEWORK") || !IS_FRAMEWORK)	header("Location: http://".$_SERVER["HTTP_HOST"]."/error/404");

/**
 * This is class DatabaseException that inherits Exception.
 *
 * Inherits Exception object.
 * 
 * @author	Justin Yoo
 * @package	KYR.Core
 * 
 */
class DatabaseException extends Exception
{
	private $_properties = null;
	
	/**
	 * Initiates the DatabaseException class.
	 *
	 * @access	public
	 * @param	string	$message	Error message.
	 * @param	int		$code		Error code.
	 *
	 */
	public function __construct($message = "", $code = 0)
	{
		parent::__construct($message, $code);
		$this->_properties = array();
	}

	/**
	 * Returns the property called by name.
	 *
	 * @access	public
	 * @param	string	$name	Name of the property.
	 * @return	mixed			Returns the named property.
	 *
	 */
	public function __get($name)
	{
		if (array_key_exists($name, $this->_properties))
			return $this->_properties[$name];
		else
			return null;
	}
	
	/**
	 * Sets the property to the given name.
	 *
	 * @access	public
	 * @param	string	$name	Name of the property.
	 * @param	mixed	$value	Value of the property.
	 *
	 */
	public function __set($name, $value)
	{
		$this->_properties[$name] = $value;
	}
	
	/**
	 * Gets the database query causing the DatabaseException.
	 *
	 * @access	public
	 * @return	string	Returns the database query causing the DatabaseException.
	 *
	 */
	public function getQuery()
	{
		return $this->_properties["query"];
	}
}
?>
